import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';

export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;

  // cookie签名
  config.keys = appInfo.name + '_mbook20200105';

  // 框架配置
  config.middleware = [];

  // 自定义配置
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`
  };

  // Postgres 连接配置
  const sequelize = {
    dialect: 'postgres', // 数据库类型，支持 mysql, mariadb, postgres, mssql
    database: 'mbook',
    host: '127.0.0.1',
    port: '5432',
    username: 'mbook',
    password: '121960425mbook',
    baseDir: 'model', // 加载所有model目录下的模型
    define: {
      underscored: true, // 将所有属性转换成下划线分隔的形式存储
      freezeTableName: true // 禁用讲表格名转为负数存储
    }
  };

  return {
    ...config,
    ...bizConfig,
    sequelize
  };
};
